﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Web.UI;

namespace ExtJSExtender.Controls
{
    [Serializable]
    public class TreeNode
    {
        #region 构造函数

        public TreeNode()
        {

        }

        #endregion

        #region 属性

        /// <summary>
        /// 获取或设置节点的id
        /// </summary>
        public string id { get; set; }

        /// <summary>
        /// 获取或设置节点的text
        /// </summary>
        public string text { get; set; }

        /// <summary>
        /// 获取或设置节点是否可以拖拽
        /// </summary>
        public bool? draggable { get; set; }

        /// <summary>
        /// 获取或设置节点是否可以拖拽
        /// </summary>
        public bool? expanded { get; set; }

        /// <summary>
        /// 获取或设置节点是否为叶子节点，如果存在子节点则返回false
        /// </summary>
        public bool? leaf { get; set; }

        /// <summary>
        /// 获取或设置节点是否为根节点
        /// </summary>
        public bool? root { get; set; }

        /// <summary>
        /// 获取或设置节点的css样式，用来设置一个不同的icon图标
        /// </summary>
        public string cls { get; set; }

        /// <summary>
        /// 父节点ID
        /// </summary>
        public string parentId { get; set; }

        /// <summary>
        ///  要导航到的地址
        /// </summary>
        public string href { get; set; }

        /// <summary>
        /// 打开地址的目标
        /// </summary>
        public string hrefTarget { get; set; }

        /// <summary>
        /// 节点的icon地址。推荐使用cls或者iconCls属性，在css中添加背景图片来设置icon
        /// </summary>
        public string icon { get; set; }

        /// <summary>
        /// 节点是否被勾选，只有当节点是checkbox tree是可用
        /// </summary>
        public bool? isChecked { get; set; }

        private bool? _loaded = null;
        /// <summary>
        /// 是否加载完成
        /// </summary>
        public bool loaded
        {
            get
            {
                if (_loaded.HasValue)
                    return _loaded.Value;

                return !(_children == null || _children.Count == 0);
            }
            set
            {
                this._loaded = value;
            }
        }

        private TreeNodeCollection _children = null;
        /// <summary>
        /// 子节点
        /// </summary>
        [PersistenceMode(PersistenceMode.InnerProperty), Bindable(true), Localizable(true)]
        public TreeNodeCollection children
        {
            get
            {
                if (_children == null)
                    _children = new TreeNodeCollection();

                return _children;
            }
            set { _children = value; }
        }

        #endregion

        ///// <summary>
        ///// Gets or sets the type of the node.
        ///// </summary>
        ///// <value>The type of the node.</value>
        //public string NodeType { get; set; }

        ///// <summary>
        ///// The quick tip config for the node
        ///// </summary>
        //public string qtipCfg { get; set; }

        ///// <summary>
        ///// private
        ///// </summary>
        //public bool childrenRendered { get; set; }
    }


}
